package com.lagou;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.CombineTextInputFormat;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

import java.io.IOException;

public class SortDriver {
    public static void main(String[] args) throws IOException, ClassNotFoundException, InterruptedException {
        Configuration conf = new Configuration();
        Job job = Job.getInstance(conf, "SortDriver");
        //设置jar包本地路径
        job.setJarByClass(SortDriver.class);
        //使用的mapper和reducer
        job.setMapperClass(SortMapper.class);
        job.setReducerClass(SortReducer.class);
        //map的输出kv类型
        job.setMapOutputKeyClass(SortBean.class);
        job.setMapOutputValueClass(NullWritable.class);
        //reducer的输出kv类型
        job.setOutputKeyClass(SortBean.class);
        job.setOutputValueClass(NullWritable.class);
        //设置读取文件类型
        job.setInputFormatClass(CombineTextInputFormat.class);
        //读取的数据路径
        FileInputFormat.setInputPaths(job,new Path(args[0]));
        //输出的数据路径
        FileOutputFormat.setOutputPath(job,new Path(args[1]));
        //提交任务
        boolean flag = job.waitForCompletion(true);
        System.exit(flag ? 0 : 1);

    }
}
